#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <strings.h>

#include "button.h"

int main(void)
{
	int fd;
	int on = 0xFF;
	struct BUTTON button;
	
	/*打开设备文件*/
	fd = open("/dev/button",O_RDWR);
	if(fd < 0)
	{
		perror("open");
		return 1;
	}

	/*读写设备文件*/
	while(1)
	{
		bzero(&button, sizeof(button));
		read(fd, &button, sizeof(button));

		if (button.code == 'A')
		{
			if (button.value == 1) 
				printf("power key pressed.\n");
			else
				printf("power key released.\n");
		}
	}

	/*关闭设备文件*/	
	close(fd);

	return 0;
}
